/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cgi.ndk.wf.task;

import com.cgi.ndk.wf.generated.endToEndProcessOnly.EndToEndProcessOnlyResponse;
import com.cgi.ndk.wf.generated.endToEndTest.EndToEndTestResponse;
import com.cgi.ndk.wf.generated.humanTaskService.CompleteResponse;
import com.cgi.ndk.wf.generated.humanTaskService.LoadTaskResponse;
import com.cgi.ndk.wf.generated.humanTaskService.SimpleQueryResponse;
import com.cgi.ndk.wf.generated.humanTaskService.StartResponse;
import com.cgi.ndk.wf.generated.instanceManagementService.InstanceInfoType;
import com.cgi.ndk.wf.generated.instanceManagementService.PaginatedInstanceList;
import com.cgi.ndk.wf.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author kovalcikm
 */
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @RequestMapping(value = "/getAutomaticTasks", produces = "application/json")
    public PaginatedInstanceList getInstances() {
        return taskService.getInstances();
    }

    @RequestMapping(value = "/getAutomaticTask/{id}", produces = "application/json")
    public InstanceInfoType getPackages(@PathVariable("id") String id) {
        //todo check parameter
        return taskService.getAutomaticTask(Long.parseLong(id));
    }

    //operations with human tasks:
    @RequestMapping(value = "/getHumanTasks", produces = "application/json")
    public SimpleQueryResponse getHumanTasks() {
        //todo check parameter
        return taskService.getHumanTasks();
    }

    @RequestMapping(value = "/reserve/{id}", produces = "application/json")
    public StartResponse reserve(@PathVariable("id") String id) {
        return taskService.reserve(id);
    }

    @RequestMapping(value = "/load/{id}", produces = "application/json")
    public LoadTaskResponse load(@PathVariable("id") String id) {
        return taskService.load(id);
    }

    @RequestMapping(value = "/complete/{id}", produces = "application/json")
    public CompleteResponse complete(@PathVariable("id") String id) {
        return taskService.complete(id);
    }

    @RequestMapping(value = "/endToEndProcessOnly/{id}", produces = "application/json")
    public EndToEndProcessOnlyResponse endToEndProcessOnly(@PathVariable("id") String id) {
        return taskService.endToEndProcessOnly(id); 
    }

    @RequestMapping(value = "/endToEndTest/{id}", produces = "application/json")
    public EndToEndTestResponse endToEndTest(@PathVariable("id") String id) {
        return taskService.endToEndTest(id);
    }

}
